package com.zbl.zblproject.erp.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zbl.zblproject.erp.entity.ErpOweGoodsItem;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author youlanqiang
 * @version 1.0
 * @date 2018/10/29
 */
@Repository
public interface ErpOweGoodsItemMapper extends BaseMapper<ErpOweGoodsItem> {

    List<String> getOrderSns();

    /**
     * 查询订单号根据OrderSn
     * @param mode
     * @return
     */
    @Select("SELECT  DISTINCT order_sn FROM zbl_erp_owegoodsitem WHERE mode = #{mode} AND number != 0")
    List<String> getOrderSnsByMode(@Param("mode") int mode);

    @Delete("DELETE FROM zbl_erp_owegoodsitem WHERE erp_order_item_id = #{id}")
    boolean deleteByErpItemId(@Param("id") int id);

    @Delete("DELETE FROM zbl_erp_owegoodsitem WHERE item_id = #{id}")
    boolean deleteByItemId(@Param("id") int id);

    @Update("UPDATE zbl_erp_owegoodsitem SET mode = 2 WHERE order_sn = #{orderSn} ")
    boolean changeOrderSn(@Param("orderSn") String orderSn);

    /**
     * 订单MODE设置为 3 设置为终结
     * @param orderSn
     * @return
     */
    @Update("UPDATE zbl_erp_owegoodsitem SET mode = 3 WHERE order_sn = #{orderSn} ")
    boolean changeOrderSnToEnded(@Param("orderSn") String orderSn);

    @Select("SELECT * FROM zbl_erp_owegoodsitem WHERE mode != 3 AND number > 0 AND order_sn = #{orderSn}")
    List<ErpOweGoodsItem> selectListByOrderSn(@Param("orderSn") String orderSn);
}
